//
//  UserHeaderView.m
//  CookieTrip
//
//  Created by dllo on 16/1/7.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "UserHeaderView.h"

@implementation UserHeaderView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self create];
    }
    return self;
}

- (void)create{
    
    self.myimage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"user.jpg"]];
    self.myimage.frame = CGRectMake(0, -64, 414, 314*736/736);
    [self addSubview:self.myimage];

    if ([[NSUserDefaults standardUserDefaults]boolForKey:@"login"] == NO) {
        self.photo = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"user.jpg"]];
    }else{
        NSURL *url = [NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:@"icon"]];
        NSLog(@"%@",[[NSUserDefaults standardUserDefaults]objectForKey:@"icon"]);
        NSData *data = [NSData dataWithContentsOfURL:url];
        self.photo = [[UIImageView alloc]initWithImage:[UIImage imageWithData:data]];
           }
    self.photo.frame = CGRectMake(344*414/828, 120*736/736, 70*736/736, 70*736/736);
    self.photo.layer.cornerRadius = 35*736/736;
    self.photo.layer.masksToBounds = YES;
    [self.myimage addSubview:self.photo];
    
    self.btn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.btn.frame = CGRectMake(157*414/414, 160*736/736, 100*414/414, 35*736/736);
    [self addSubview:self.btn];
    self.btn.layer.cornerRadius = 15;
    
    
    if ([[NSUserDefaults standardUserDefaults]boolForKey:@"login"] == NO) {
       [self.btn setTitle:@"登陆" forState:UIControlStateNormal];
    }else{
       [self.btn setTitle:@"注销" forState:UIControlStateNormal];
    }
    
    [self.btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    //self.btn.backgroundColor = TianQing;
    [self.btn addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchUpInside];
    
}

-(void)login{
   
   // [self.loginDelegate goToSina];

}





@end
